#pragma once

#include "CombinedFragment.h"

#include "Gate.h"
#include "InteractionOperand.h"

namespace uml {

CombinedFragment::CombinedFragment(const QString& umlType)
    : NamedElement(umlType) {}

void CombinedFragment::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    InteractionFragment::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(cfragmentGates_, "cfragmentGates", json, errorList);
    interactionOperator_ = (InteractionOperatorKind)json.value("interactionOperator").toInt((int)interactionOperator_);
    JsonSerializable::fromJsonArray(operands_, "operands", json, errorList);
}

void CombinedFragment::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    InteractionFragment::toJson(json);
    JsonSerializable::toJsonArray(cfragmentGates_, "cfragmentGates", json);
    json.insert("interactionOperator", (int)interactionOperator_);
    JsonSerializable::toJsonArray(operands_, "operands", json);
}

/// <summary>
/// cfragmentGates getter
/// Specifies the gates that form the interface between this CombinedFragment and
/// its surroundings
/// </summary>
vector<shared_ptr<Gate>>& CombinedFragment::cfragmentGates() {
    return cfragmentGates_;
}

/// <summary>
/// interactionOperator getter
/// Specifies the operation which defines the semantics of this combination of
/// InteractionFragments.
/// </summary>
InteractionOperatorKind CombinedFragment::interactionOperator() const {
    return interactionOperator_;
}

/// <summary>
/// interactionOperator setter
/// Specifies the operation which defines the semantics of this combination of
/// InteractionFragments.
/// </summary>
void CombinedFragment::setInteractionOperator(InteractionOperatorKind value) {
    interactionOperator_ = value;
}

/// <summary>
/// operands getter
/// The set of operands of the combined fragment.
/// </summary>
vector<shared_ptr<InteractionOperand>>& CombinedFragment::operands() {
    return operands_;
}

} // namespace uml
